import React, { useState } from 'react';
import './App.css';
import { Button, Upload } from 'antd'
import { UploadChangeParam, UploadFile } from 'antd/es/upload';
function App() {
  const [url, setUrl] = useState('')
  const handleChange = (info: UploadChangeParam<UploadFile<any>>) => {
    // console.log(info)
    // 判断后端是否返回结果
    if(info.file.response) {
      const { data: { url } } = info.file.response;
      setUrl(url)
    }
  }
  return (
    <div className="App">
      <Upload action="/api/upload" onChange={(info) => handleChange(info)}>
        <Button>上传图片</Button>
      </Upload>

      <img src={url} alt="" height={500}/>
    </div>
  );
}

export default App;
